package com.ylbh.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.sql.SQLException;

//@Configuration
public class DruidConfig {

//    private Logger logger = LoggerFactory.getLogger(DruidConfig.class);
//
//    @Value("${spring.datasource.druid.url}")
//    public String url;
//
//    @Value("${spring.datasource.druid.username}")
//    public String username;
//
//    @Value("${spring.datasource.druid.password}")
//    public String password;
//
//    @Value("${spring.datasource.druid.initial-size}")
//    public int initialSize;
//
//    @Value("${spring.datasource.druid.max-active}")
//    public int maxActive;
//
//    @Value("${spring.datasource.druid.min-idle}")
//    public int minIdle;
//
//    @Value("${spring.datasource.druid.max-wait}")
//    public int maxWait;
//
//    @Value("${spring.datasource.druid.pool-prepared-statements}")
//    public Boolean poolPreparedStatements;
//
//    @Value("${spring.datasource.druid.max-pool-prepared-statement-per-connection-size}")
//    public int maxPoolPreparedStatementPerConnectionSize;
//
//    @Value("${spring.datasource.druid.time-between-eviction-runs-millis}")
//    public int timeBetweenEvictionRunsMillis;
//
//    @Value("${spring.datasource.druid.min-evictable-idle-time-millis}")
//    public int minEvictableIdleTimeMillis;
//
//    @Value("${spring.datasource.druid.test-while-idle}")
//    public Boolean testWhileIdle;
//
//    @Value("${spring.datasource.druid.test-on-borrow}")
//    public Boolean testOnBorrow;
//
//    @Value("${spring.datasource.druid.test-on-return}")
//    public Boolean testOnReturn;
//
//    @Value("${spring.datasource.druid.stat-view-servlet.enabled}")
//    public Boolean enabled;
//
//    @Value("${spring.datasource.druid.stat-view-servlet.url-pattern}")
//    public String urlPattern;
//
//    @Value("${spring.datasource.druid.filter}")
//    public String filter;
//
//    @Value("${spring.datasource.connection-properties}")
//    public String connectionProperties;
//
////    @Value("${spring.datasource.druid.filter.stat.log-slow-sql}")
////    public Boolean logSlowSql;
////
////    @Value("${spring.datasource.druid.filter.stat.slow-sql-millis}")
////    public int slowSqlMillis;
////
////    @Value("${spring.datasource.druid.filter.stat.merge-sql}")
////    public Boolean mergeSql;
////
////    @Value("${spring.datasource.druid.filter.config.multi-statement-allow}")
////    public Boolean multiStatementAllow;
//
//    @Bean     //声明其为Bean实例
//    @Primary  //在同样的DataSource中，首先使用被标注的DataSource
//    public DataSource dataSource() throws Exception {
//        DruidDataSource datasource = new DruidDataSource();
//        datasource.setUrl(this.url);
//        datasource.setUsername(username);
//        datasource.setPassword(password);
//        datasource.setInitialSize(initialSize);
//        datasource.setMaxActive(maxActive);
//        datasource.setMinIdle(minIdle);
//        datasource.setMaxWait(maxWait);
//        datasource.setPoolPreparedStatements(poolPreparedStatements);
//        datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
//        datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
//        datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
//        datasource.setTestWhileIdle(testWhileIdle);
//        datasource.setTestOnBorrow(testOnBorrow);
//        datasource.setTestOnReturn(testOnReturn);
//        datasource.setEnable(enabled);
//        try {
//            datasource.setFilters(filter);
//        } catch (SQLException e) {
//            logger.error("druid configuration initialization filter", e);
//        }
//        datasource.setConnectionProperties(connectionProperties);
//        return datasource;
//    }

}
